import { mapGetters } from 'vuex';
import { deleteConfig } from '@/api/system/tbSysConfig';
export default {
	props: {
		data: { type: Array, default: () => [] },
		type: String
	},
	components: {},
	data() {
		return {
			formDialog: false,
			dataId: null
		}
	},
	methods: {
		handleOpenDialog(id) {
			this.dataId = id;
			this.formDialog = true;
		},

		//删除配置
		handleDeleteConfig(id) {
			let that = this;
			if (this.data.some(n => n.pid === id)) {
				this.$showCustomMessage('warning', `该数据存在子数据，请先删除子数据`);
				return false;
			}
			this.$confirm('确认删除？删除之后不再恢复', '提示', {
				type: 'warning',
				async beforeClose(action, instance, done) {
					if (action === 'confirm') {
						instance.confirmButtonLoading = true;
						await that.deleteConfigRequest(id);
						instance.confirmButtonLoading = false;
						done();
					} else {
						done();
					}
				}
			}).catch((_) => {});
		},

		//删除请求
		async deleteConfigRequest(id) {
			let result = await deleteConfig(id).then((res) => res.data);
			if (result.code === '0') {
				this.$showCustomMessage('success', `删除配置成功`);
				this.$emit('refresh');
			}
		},

		handleUpdateData() {
			this.$emit('refresh');
		}
	}
}